const db = require('../db/index')
const fs = require('fs')
const path = require('path')
const basePath = __dirname + '/../upload/'
const {baseURL} = require('../config')
exports.uploadFile = (req, res)=>{
  const extname = req.files[0].originalname;
  const suffix = extname.split('.')[1];
  const filename = req.files[0].filename;
  const file = fs.readFileSync(basePath + filename)
  const url = basePath + filename + '.' + suffix;
  //文件操作：将上传的文件写入到对应文件夹中
  fs.writeFileSync(url,file)
  fs.unlinkSync(basePath+filename)
  res.send({
    status:0,
    message:'上传成功',
    data: baseURL + '/upload/' + filename  + '.' + suffix
  })
}